<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Member extends Authenticatable implements JWTSubject
{
    use Notifiable;
    use HasDateTimeFormatter;
    protected $table = 'member';

    protected $primaryKey = 'userid';

    public $timestamps = false;
    protected $dateFormat = 'U';
    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';

    protected $fillable = [
        'username',
        'password',
        'phone',
        'reg_ip',
        'add_time',
        'status',
        'userTypeId',
        'json',
    ];


    // 用户医生资格认证 一对一
    public function doctor()
    {
        return $this->hasOne(MemberDoctor::class, 'user_id', 'userid');
    }



    /**
     * 获取创建时间
     *
     * @param  string  $value
     * @return string
     */
    public function getCreateTimeAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    /**
     * 获取修改时间
     *
     * @param  string  $value
     * @return string
     */
    public function getUpdateTimeAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }


    protected static function boot()
    {
        parent::boot();
        static::deleting(function ($user) {
            // $user->wx()->delete();
            $user->doctor()->delete();
        });
    }
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
}
